package com.kate.mall.order.state;


import com.kate.mall.common.utils.DateProvider;
import com.kate.mall.order.dao.OrderDao;
import com.kate.mall.order.dto.OrderDTO;
import com.kate.mall.order.entity.OrderEntity;

/**
 * @Description: 模模板方法模式抽取订单状态的处理逻辑
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/30 09:55
 */
public abstract class AbstractOrderState implements OrderState {

    private OrderDao orderDao;

    private DateProvider dateProvider;
    public AbstractOrderState(OrderDao orderDao,DateProvider dateProvider){
        this.dateProvider=dateProvider;
        this.orderDao=orderDao;
    }

    /**
     * 订单状态的处理流程
     * @param order 订单
     * @throws Exception
     */
    public void doTransition(OrderDTO order) throws Exception {
        //1.获取订单状态
        Integer orderStatus =  getOrderStatus(order);
        //2.设置订单状态
        order.setOrderStatus(orderStatus);
        //3.更新数据库订单状态
        OrderEntity orderEntity = new OrderEntity(order.getId(),orderStatus);
        orderDao.updateById(orderEntity);
    }
    /**
     * 获取订单状态
     * @param order 订单
     * @return 订单状态
     * @throws Exception
     */
    public abstract Integer getOrderStatus(OrderDTO order) ;
    /**
     * 判断当前状态下能否执行取消订单操作
     * @param order 订单
     * @return 能否执行取消订单操作
     */
    public Boolean canCancel(OrderDTO order) throws Exception {
        return false;
    }
    /**
     * 判断订单能否执行支付操作
     * @param order 订单
     * @return 能否执行支付操作
     * @throws Exception
     */
    public Boolean canPay(OrderDTO order) throws Exception {
        return false;
    }
    /**
     * 判断能否执行手动确认收货的操作
     * @param order 订单
     * @return 能否执行手动确认收货的操作
     * @throws Exception
     */
    public Boolean canConfirmReceipt(OrderDTO order) throws Exception {
        return false;
    }
    /**
     * 判断能否申请退货
     * @param order 订单
     * @return 能否申请退货
     * @throws Exception
     */
    public Boolean canApplyReturnGoods(OrderDTO order) throws Exception {
        return false;
    }


}
